package com.sudoku.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;

import com.sudoku.common.Constants;
import com.sudoku.ui.Sudoku;
import com.sudoku.ui.content.SPanel;

public class MenuResetListener implements ActionListener {
	
	private Sudoku sudoku;
	private SPanel sPanel;
	public MenuResetListener(Sudoku sudoku) {
		this.sudoku = sudoku;
		this.sPanel = sudoku.getPanel();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.sPanel = sudoku.getPanel(); // 重新获取一遍SPanel，因为在选择难度时生成了新的sPanel
		boolean[][] mask = sPanel.getMask();
		JTextField[][] jTextFields = sPanel.getTfCells();
		
		for (int row = 0; row < Constants.GRID_SIZE; row++) {
			for (int col = 0; col < Constants.GRID_SIZE; col++) {
				if (mask[row][col]) {
					jTextFields[row][col].setText("");
					jTextFields[row][col].setBackground(Constants.OPEN_CELL_BGCOLOR);
				}
			}
		}
		
		sPanel.getFilledCellCnt();
		sPanel.getStatus().update();
	}

}
